package com.linktel.productionLine.controller;

import com.linktel.productionLine.common.BaseResponse;
import com.linktel.productionLine.common.ErrorCode;
import com.linktel.productionLine.common.ResultUtils;
import com.linktel.productionLine.entity.dto.productionLine.ProductionLineDTO;
import com.linktel.productionLine.exception.BusinessException;
import com.linktel.productionLine.service.ProductionLineService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 对产线的有关请求
 *
 * @Author HuangJiaHui
 * @Date 2023/8/25 10:18
 */
@RestController
@RequestMapping("/production-line")
@AllArgsConstructor
public class ProductionLineController {

    protected ProductionLineService productionLineService;

    /**
     * 查询当前用户对应产线的信息
     * 如果commitUserId为空，则返回所有产线
     *
     * @param commitUserId 用户Id
     * @return 产线信息列表
     */
    @GetMapping
    public BaseResponse<List<ProductionLineDTO>> listProductionLine(Long commitUserId) {
        List<ProductionLineDTO> productionLineNames = productionLineService.listProductionLine(commitUserId);
        return ResultUtils.success(productionLineNames);
    }

    /**
     * 查询当前用户在已经定义月度计划的产线列表
     *
     * @param commitUserId 用户Id
     * @return 产线信息列表
     */
    @GetMapping("/monthlyPlanning")
    public BaseResponse<List<ProductionLineDTO>> listProductionLineByMonthlyPlanning(Long commitUserId) {
        if (commitUserId == null || commitUserId <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户id不能为空");
        }
        List<ProductionLineDTO> productionLineNames = productionLineService.listProductionLineByMonthlyPlanning(commitUserId);
        return ResultUtils.success(productionLineNames);
    }
}
